<template>
  <div class="app-container">
    <el-row>
      <!-- 产品工艺 -->
      <el-col :span="24" class="card-box">
        <el-card>
          <el-form
            :model="queryPTParams"
            ref="queryPTForm"
            :inline="true"
            v-show="showPTSearch"
            label-width="68px"
          >
            <!-- <el-form-item label="产品工艺编号" prop="smesProductTechNo">
        <el-input
          v-model="queryPTParams.smesProductTechNo"
          placeholder="请输入产品工艺编号"
          clearable
          size="small"
          @keyup.enter.native="handlePTQuery"
        />
      </el-form-item> -->
            <el-form-item label="产品编号" prop="productNo">
              <el-input
                v-model="queryPTParams.productNo"
                placeholder="请输入产品编号"
                clearable
                size="small"
                @keyup.enter.native="handlePTQuery"
              />
            </el-form-item>
            <el-form-item label="产品名称" prop="productName">
              <el-input
                v-model="queryPTParams.productName"
                placeholder="请输入产品编号"
                clearable
                size="small"
                @keyup.enter.native="handlePTQuery"
              />
            </el-form-item>
            <el-form-item label="工艺编号" prop="techProcessNo">
              <el-input
                v-model="queryPTParams.techProcessNo"
                placeholder="请输入工艺编号"
                clearable
                size="small"
                @keyup.enter.native="handlePTQuery"
              />
            </el-form-item>
            <el-form-item label="工艺名称" prop="techProcessName">
              <el-input
                v-model="queryPTParams.techProcessName"
                placeholder="请输入工艺编号"
                clearable
                size="small"
                @keyup.enter.native="handlePTQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="cyan"
                icon="el-icon-search"
                size="mini"
                @click="handlePTQuery"
                >搜索</el-button
              >
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetPTQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleTPExport"
                v-hasPermi="['production:productTech:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showPTSearch"
              @queryTable="getPTList"
            ></right-toolbar>
          </el-row>

          <el-table
            ref="singleTable"
            border
            highlight-current-row
            v-loading="loading"
            :data="productTechList"
            @row-click="handleProductTechSelectionChange"
          >
            <el-table-column
              label="产品工艺编号"
              align="center"
              prop="smesProductTechNo"
            />
            <el-table-column label="产品编号" align="center" prop="productNo" />
            <el-table-column
              label="产品名称"
              align="center"
              prop="productName"
            />
            <el-table-column
              label="产品规格1"
              align="center"
              prop="productSpec1"
            />
            <el-table-column
              label="产品规格2"
              align="center"
              prop="productSpec2"
            />
            <el-table-column
              label="产品规格3"
              align="center"
              prop="productSpec3"
            />
            <el-table-column
              label="产品规格4"
              align="center"
              prop="productSpec4"
            />
            <el-table-column
              label="工艺编号"
              align="center"
              prop="techProcessNo"
            />
            <el-table-column
              label="工艺名称"
              align="center"
              prop="techProcessName"
            />
            <el-table-column
              label="是否有效"
              align="center"
              prop="deleteFlag"
              :formatter="deleteFlagFormat"
            />
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.createTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新者" align="center" prop="updateBy" />
            <el-table-column
              label="更新时间"
              align="center"
              prop="updateTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.updateTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleSelect(scope.row)"
                  v-hasPermi="['production:productTech:edit']"
                  >分配工艺</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="totalPT > 0"
            :total="totalPT"
            :page.sync="queryPTParams.pageNum"
            :limit.sync="queryPTParams.pageSize"
            @pagination="getPTList"
          />
          <div style="position:absolute;height:30px">
            <div style="margin-top:-20px;position:relative;float:left;">
              <label for="">{{ chosenProductTech.toString }}</label>
            </div>
          </div>
        </el-card>
      </el-col>
      <!-- 产品工艺明细 -->
      <el-col :span="18" class="card-box">
        <el-card>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['production:productTechDetail:export']"
                >导出</el-button
              >
            </el-col>
            <right-toolbar
              :showSearch.sync="showSearch"
              @queryTable="getList"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            ref="ptdTable"
            :data="productTechDetailList"
            @row-click="handleDetailRowClick"
          >
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['production:productTechDetail:edit']"
                  >修改</el-button
                >
                <!-- <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['production:productTechDetail:remove']"
                  >删除</el-button
                > -->
              </template>
            </el-table-column>
            <el-table-column label="序号" align="center" prop="rowId" />
            <el-table-column
              label="产品工艺编号"
              align="center"
              prop="smesProductTechNo"
            />
            <el-table-column
              label="流程编号"
              align="center"
              prop="techProcedureNo"
            />
            <el-table-column
              label="当前工序"
              align="center"
              prop="currentProcessName"
            />
            <el-table-column
              label="下工序"
              align="center"
              prop="nextProcessName"
            />
            <el-table-column
              label="工作中心"
              align="center"
              prop="workCenterName"
            />
            <el-table-column label="铝盖规格" align="center" prop="alCapSpec" />
            <el-table-column
              label="铝带厚度"
              align="center"
              prop="alStripThick"
            />
            <el-table-column
              label="铝盖内径"
              align="center"
              prop="alCapInDiameter"
            />
            <el-table-column
              label="铝盖内高"
              align="center"
              prop="alCapInHeight"
            />
            <el-table-column
              label="铝盖型式"
              align="center"
              prop="alCapOpenType"
              :formatter="alCapOpenTypeFormat"
            />
            <el-table-column
              label="铝盖商标"
              align="center"
              prop="alCapTrademark"
              :formatter="alCapTrademarkFormat"
            />
            <el-table-column
              label="铝带涂层"
              align="center"
              prop="alStripCoat"
              :formatter="alStripCoatFormat"
            />
            <el-table-column
              label="铝带轧制"
              align="center"
              prop="alStripCast"
              :formatter="alStripCastFormat"
            />
            <el-table-column
              label="塑盖厚度x外径x侧高"
              align="center"
              prop="plCapOutCircle"
            />
            <el-table-column
              label="塑盖颜色"
              align="center"
              prop="plCapColor"
            />
            <el-table-column
              label="色母号"
              align="center"
              prop="plCapMasterbatch"
            />
            <el-table-column
              label="塑盖形状"
              align="center"
              prop="plCapShape"
              :formatter="plCapShapeFormat"
            />
            <el-table-column
              label="塑盖表面"
              align="center"
              prop="plCapSurface"
              :formatter="plCapSurfaceFormat"
            />
            <el-table-column
              label="塑盖商标"
              align="center"
              prop="plCapTrademark"
              :formatter="plCapTrademarkFormat"
            />
            <el-table-column
              label="铆点型式"
              align="center"
              prop="plCapRivetType"
              :formatter="plCapRivetTypeFormat"
            />
            <el-table-column
              label="塑袋尺寸"
              align="center"
              prop="pkgPlbSize"
              :formatter="pkgPlbSizeFormat"
            />
            <el-table-column
              label="塑袋厚度"
              align="center"
              prop="pkgPlbThick"
              :formatter="pkgPlbThickFormat"
            />
            <el-table-column
              label="塑袋层数"
              align="center"
              prop="pkgPlbLayer"
              :formatter="pkgPlbLayerFormat"
            />
            <el-table-column
              label="封口方式"
              align="center"
              prop="pkgSealType"
              :formatter="pkgSealTypeFormat"
            />
            <el-table-column
              label="袋包装量"
              align="center"
              prop="pkgBagPackNum"
              :formatter="pkgBagPackNumFormat"
            />
            <el-table-column
              label="箱包装量"
              align="center"
              prop="pkgCasePackNum"
              :formatter="pkgCasePackNumFormat"
            />
            <el-table-column
              label="内贴标签"
              align="center"
              prop="pkgInLabel"
              :formatter="pkgInLabelFormat"
            />
            <el-table-column
              label="纸箱尺寸"
              align="center"
              prop="pkgCartonSize"
              :formatter="pkgCartonSizeFormat"
            />
            <el-table-column
              label="纸箱印刷"
              align="center"
              prop="pkgCartonPrint"
              :formatter="pkgCartonPrintFormat"
            />
            <el-table-column
              label="纸箱色条"
              align="center"
              prop="pkgCartonColor"
              :formatter="pkgCartonColorFormat"
            />
            <el-table-column
              label="纸箱层数"
              align="center"
              prop="pkgCartonLayer"
              :formatter="pkgCartonLayerFormat"
            />
            <el-table-column
              label="箱内垫板"
              align="center"
              prop="pkgPlate"
              :formatter="pkgPlateFormat"
            />
            <el-table-column
              label="标签数量"
              align="center"
              prop="pkgLabelNum"
              :formatter="pkgLabelNumFormat"
            />
            <el-table-column
              label="打包形式"
              align="center"
              prop="pkgPackType"
              :formatter="pkgPackTypeFormat"
            />
            <el-table-column
              label="印章内容"
              align="center"
              prop="pkgStampContent"
              :formatter="pkgStampContentFormat"
            />
            <el-table-column
              label="整盘包装"
              align="center"
              prop="pkgPackAll"
              :formatter="pkgPackAllFormat"
            />
            <el-table-column
              label="是否有效"
              align="center"
              prop="deleteFlag"
              :formatter="deleteFlagFormat"
            />
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.createTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新者" align="center" prop="updateBy" />
            <el-table-column
              label="更新时间"
              align="center"
              prop="updateTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.updateTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-card>
      </el-col>
      <el-col :span="6" class="card-box">
        <el-card>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="mini"
                @click="handleAddMaterial"
                v-hasPermi="['production:productTechMaterial:add']"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                icon="el-icon-edit"
                size="mini"
                :disabled="ptmSingle"
                @click="handleUpdateMaterial"
                v-hasPermi="['production:productTechMaterial:edit']"
                >修改</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                :disabled="ptmMultiple"
                @click="handleDeleteMaterial"
                v-hasPermi="['production:productTechMaterial:remove']"
                >删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleExportMaterial"
                v-hasPermi="['production:productTechMaterial:export']"
                >导出</el-button
              >
            </el-col>
          </el-row>

          <el-table
            ref="dtmTable"
            v-loading="loading"
            :data="productTechMaterialList"
            @selection-change="handleMaterialSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center" />
            <!-- <el-table-column label="工艺用料编号" align="center" prop="productTechMaterialNo" /> -->
            <el-table-column
              label="原料编号"
              align="center"
              prop="materialNo"
            />
            <el-table-column
              label="原料名称"
              align="center"
              prop="materialName"
            />
            <el-table-column
              label="原料规格"
              align="center"
              prop="materialSpec"
            />
            <el-table-column
              label="原料类型"
              align="center"
              prop="materialCategoryName"
            />
            <el-table-column label="对应重量" align="center" prop="weight" />
            <el-table-column
              label="是否有效"
              align="center"
              prop="deleteFlag"
              :formatter="deleteFlagFormat"
            />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdateMaterial(scope.row)"
                  v-hasPermi="['production:productTechMaterial:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteMaterial(scope.row)"
                  v-hasPermi="['production:productTechMaterial:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="totalMaterial > 0"
            :total="totalMaterial"
            :page.sync="queryMParams.pageNum"
            :limit.sync="queryMParams.pageSize"
            @pagination="getMaterialList"
          />
        </el-card>
      </el-col>
    </el-row>

    <!-- 选择物料对话框 -->

    <SelectMaterialDialog v-bind:open="selectMaterialOpen"
      v-on:select="confirmSelectMaterial"
      v-on:cancel="cancelSelectMaterial"/>

    <!-- 添加或修改产品工艺用料对话框 -->
    <el-dialog
      :title="ptmTitle"
      :visible.sync="ptmOpen"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="ptmForm"
        :model="ptmForm"
        :rules="ptmRules"
        label-width="80px"
      >
        <el-form-item label="工艺明细号" prop="productTechDetailId">
          <el-input
            v-model="ptmForm.productTechDetailId"
            v-bind:disabled="true"
          />
        </el-form-item>
        <el-row>
          <el-col :span="18">
            <el-form-item label="原料编号" prop="materialNo">
              <el-input v-model="ptmForm.materialNo" placeholder="请选择原料" />
            </el-form-item>
          </el-col>
          <el-col :span="6" align="center">
            <el-button type="primary" @click="handleSelectMaterial"
              >选 择</el-button
            >
          </el-col>
        </el-row>
        <el-form-item label="对应重量" prop="weight">
          <el-input v-model="ptmForm.weight" placeholder="请输入对应重量" />
        </el-form-item>
        <el-form-item label="是否有效">
          <el-radio-group v-model="ptmForm.deleteFlag">
            <el-radio
              v-for="dict in deleteFlagOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitptmForm">确 定</el-button>
        <el-button @click="cancelptm">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 产品工艺分配 -->
    <el-dialog
      :title="ptTitle"
      :visible.sync="ptOpen"
      width="1000px"
      append-to-body
      @open="initPTDialog"
      :close-on-click-modal="false"
    >
      <div style="height:600px">
        <el-col :span="24" class="card-box">
          <el-card>
            <div style="margin: 20px">
              <label for=""
                >产品:{{ formPT.productNo }},名称：{{
                  formPT.productName
                }}</label
              >
            </div>
          </el-card>

          <el-card>
            <el-table
              height="400px"
              ref="tptable"
              v-loading="loading"
              :data="techProcessList"
              @selection-change="rowTPClick"
            >
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column
                label="工艺编号"
                align="center"
                prop="techProcessNo"
              />
              <el-table-column
                label="工艺名称"
                align="center"
                prop="techProcessName"
              />
              <el-table-column
                label="工艺描述"
                align="center"
                prop="techProcessDesc"
              />
              <el-table-column
                label="是否有效"
                align="center"
                prop="deleteFlag"
                :formatter="deleteFlagFormat"
              />
            </el-table>

            <pagination
              v-show="totalTP > 0"
              :total="totalTP"
              :page.sync="queryPTParams.pageNum"
              :limit.sync="queryPTParams.pageSize"
              @pagination="getTechProcessList"
            />
          </el-card>
        </el-col>

        <el-form label-width="100px">
          <el-form-item
            style="text-align: center;margin-left:-100px;margin-top:50px;"
          >
            <el-button type="primary" @click="submitPTForm">确 定</el-button>
            <el-button @click="cancelPT">取 消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>

    <!-- 添加或修改产品工艺明细对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item
          label="产品工艺编号"
          prop="smesProductTechNo"
          label-width="120px"
        >
          <el-input
            v-model="form.smesProductTechNo"
            v-bind:disabled="disableEdit"
          />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="流程编号">
              <el-input
                v-bind:disabled="disableEdit"
                v-model="form.techProcedureNo"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="流程名称" prop="techProcedureName">
              <el-input
                v-model="form.techProcedureName"
                v-bind:disabled="disableEdit"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="当前工序" prop="currentProcessName">
              <el-input
                v-model="form.currentProcessName"
                v-bind:disabled="disableEdit"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下工序" prop="nextProcessName">
              <el-input
                v-model="form.nextProcessName"
                v-bind:disabled="disableEdit"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div v-show="isAlShow">
          <el-row>
            <el-col :span="6">
              <el-form-item label="铝盖规格" prop="alCapSpec">
                <el-input
                  v-model="form.alCapSpec"
                  placeholder="请输入铝盖规格"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="铝带厚度" prop="alStripThick">
                <el-input
                  v-model="form.alStripThick"
                  placeholder="请输入铝带厚度"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="铝盖内径" prop="alCapInDiameter">
                <el-input
                  v-model="form.alCapInDiameter"
                  placeholder="请输入铝盖内径"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="铝盖内高" prop="alCapInHeight">
                <el-input
                  v-model="form.alCapInHeight"
                  placeholder="请输入铝盖内高"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="铝盖型式" prop="alCapOpenType">
                <el-select
                  v-model="form.alCapOpenType"
                  placeholder="请选择铝盖型式"
                >
                  <el-option
                    v-for="dict in alCapOpenTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="铝盖商标" prop="alCapTrademark">
                <el-select
                  v-model="form.alCapTrademark"
                  placeholder="请选择铝盖商标"
                >
                  <el-option
                    v-for="dict in alCapTrademarkOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="铝带涂层" prop="alStripCoat">
                <el-select
                  v-model="form.alStripCoat"
                  placeholder="请选择铝带涂层"
                >
                  <el-option
                    v-for="dict in alStripCoatOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="铝带轧制" prop="alStripCast">
                <el-select
                  v-model="form.alStripCast"
                  placeholder="请选择铝带轧制"
                >
                  <el-option
                    v-for="dict in alStripCastOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
        </div>
        <div v-show="isPlShow">
          <el-row>
            <el-col :span="12"
              ><el-form-item
                label="塑盖厚度x外径x侧高"
                prop="plCapOutCircle"
                label-width="120px"
              >
                <el-input
                  v-model="form.plCapOutCircle"
                  placeholder="请输入塑盖厚度x外径x侧高"
                /> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="塑盖颜色" prop="plCapColor">
                <el-input
                  v-model="form.plCapColor"
                  placeholder="请输入塑盖颜色"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6"
              ><el-form-item label="色母号" prop="plCapMasterbatch">
                <el-input
                  v-model="form.plCapMasterbatch"
                  placeholder="请输入色母号"
                /> </el-form-item
            ></el-col>
          </el-row>
          <el-row>
            <el-col :span="6"
              ><el-form-item label="塑盖形状" prop="plCapShape">
                <el-select
                  v-model="form.plCapShape"
                  placeholder="请选择塑盖形状"
                >
                  <el-option
                    v-for="dict in plCapShapeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6">
              <el-form-item label="塑盖表面" prop="plCapSurface">
                <el-select
                  v-model="form.plCapSurface"
                  placeholder="请选择塑盖表面"
                >
                  <el-option
                    v-for="dict in plCapSurfaceOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6">
              <el-form-item label="塑盖商标" prop="plCapTrademark">
                <el-select
                  v-model="form.plCapTrademark"
                  placeholder="请选择塑盖商标"
                >
                  <el-option
                    v-for="dict in plCapTrademarkOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="铆点型式" prop="plCapRivetType">
                <el-select
                  v-model="form.plCapRivetType"
                  placeholder="请选择铆点型式"
                >
                  <el-option
                    v-for="dict in plCapRivetTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
        </div>
        <div v-show="isPKGShow">
          <el-row>
            <el-col :span="6">
              <el-form-item label="塑袋尺寸" prop="pkgPlbSize">
                <el-select
                  v-model="form.pkgPlbSize"
                  placeholder="请选择塑袋尺寸"
                >
                  <el-option
                    v-for="dict in pkgPlbSizeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6"
              ><el-form-item label="塑袋厚度" prop="pkgPlbThick">
                <el-select
                  v-model="form.pkgPlbThick"
                  placeholder="请选择塑袋厚度"
                >
                  <el-option
                    v-for="dict in pkgPlbThickOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="塑袋层数" prop="pkgPlbLayer">
                <el-select
                  v-model="form.pkgPlbLayer"
                  placeholder="请选择塑袋层数"
                >
                  <el-option
                    v-for="dict in pkgPlbLayerOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="封口方式" prop="pkgSealType">
                <el-select
                  v-model="form.pkgSealType"
                  placeholder="请选择封口方式"
                >
                  <el-option
                    v-for="dict in pkgSealTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
          <el-row>
            <el-col :span="6"
              ><el-form-item label="袋包装量" prop="pkgBagPackNum">
                <el-select
                  v-model="form.pkgBagPackNum"
                  placeholder="请选择袋包装量"
                >
                  <el-option
                    v-for="dict in pkgBagPackNumOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="箱包装量" prop="pkgCasePackNum">
                <el-select
                  v-model="form.pkgCasePackNum"
                  placeholder="请选择箱包装量"
                >
                  <el-option
                    v-for="dict in pkgCasePackNumOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="内贴标签">
                <el-radio-group v-model="form.pkgInLabel">
                  <el-radio
                    v-for="dict in pkgInLabelOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                    >{{ dict.dictLabel }}</el-radio
                  >
                </el-radio-group>
              </el-form-item></el-col
            >
            <el-col :span="6"
              ><el-form-item label="纸箱尺寸" prop="pkgCartonSize">
                <el-select
                  v-model="form.pkgCartonSize"
                  placeholder="请选择纸箱尺寸"
                >
                  <el-option
                    v-for="dict in pkgCartonSizeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="纸箱印刷" prop="pkgCartonPrint">
                <el-select
                  v-model="form.pkgCartonPrint"
                  placeholder="请选择纸箱印刷"
                >
                  <el-option
                    v-for="dict in pkgCartonPrintOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="纸箱色条" prop="pkgCartonColor">
                <el-select
                  v-model="form.pkgCartonColor"
                  placeholder="请选择纸箱色条"
                >
                  <el-option
                    v-for="dict in pkgCartonColorOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="纸箱层数" prop="pkgCartonLayer">
                <el-select
                  v-model="form.pkgCartonLayer"
                  placeholder="请选择纸箱层数"
                >
                  <el-option
                    v-for="dict in pkgCartonLayerOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="箱内垫板" prop="pkgPlate">
                <el-select v-model="form.pkgPlate" placeholder="请选择箱内垫板">
                  <el-option
                    v-for="dict in pkgPlateOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
          </el-row>
          <el-row>
            <el-col :span="6"
              ><el-form-item label="标签数量" prop="pkgLabelNum">
                <el-select
                  v-model="form.pkgLabelNum"
                  placeholder="请选择标签数量"
                >
                  <el-option
                    v-for="dict in pkgLabelNumOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="打包形式" prop="pkgPackType">
                <el-select
                  v-model="form.pkgPackType"
                  placeholder="请选择打包形式"
                >
                  <el-option
                    v-for="dict in pkgPackTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="印章内容" prop="pkgStampContent">
                <el-select
                  v-model="form.pkgStampContent"
                  placeholder="请选择印章内容"
                >
                  <el-option
                    v-for="dict in pkgStampContentOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="整盘包装">
                <el-radio-group v-model="form.pkgPackAll">
                  <el-radio
                    v-for="dict in pkgPackAllOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                    >{{ dict.dictLabel }}</el-radio
                  >
                </el-radio-group>
              </el-form-item></el-col
            >
          </el-row>
        </div>
        <el-form-item label="是否有效">
          <el-radio-group v-model="form.deleteFlag">
            <el-radio
              v-for="dict in deleteFlagOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProductTech,
  getProductTech,
  delProductTech,
  addProductTech,
  updateProductTech,
  exportProductTech
} from "@/api/production/productTech";
import { listTechProcess } from "@/api/production/techProcess";
import SelectMaterialDialog from "@/components/Simpsense/SelectMaterialDialog";
import {
  listProductTechDetail,
  getProductTechDetail,
  delProductTechDetail,
  addProductTechDetail,
  updateProductTechDetail,
  exportProductTechDetail
} from "@/api/production/productTechDetail";
import {
  listProductTechMaterial,
  getProductTechMaterial,
  delProductTechMaterial,
  addProductTechMaterial,
  updateProductTechMaterial,
  exportProductTechMaterial
} from "@/api/production/productTechMaterial";

export default {
  name: "ProductTech",
  components: {SelectMaterialDialog},
  data() {
    return {
      //工艺用料变量----------------------------------------------------------------------------------------------
      //选择物料相关变量
      //是否弹出
      selectMaterialOpen: false,
      // 选中数组
      ptmIds: [],
      // 非单个禁用
      ptmSingle: true,
      // 非多个禁用
      ptmMultiple: true,
      // 总条数
      totalMaterial: 0,
      // 产品工艺用料表格数据
      productTechMaterialList: [],
      // 弹出层标题
      ptmTitle: "",
      // 是否显示弹出层
      ptmOpen: false,

      selectedDetailId: 0,
      // 查询参数
      queryMParams: {
        pageNum: 1,
        pageSize: 10,
        materialNo: null,
        productTechDetailId: null
      },
      // 表单参数
      ptmForm: {},
      // 表单校验
      ptmRules: {
        materialNo: [
          { required: true, message: "原料编号不能为空", trigger: "blur" }
        ]
      },
      //工艺用料变量----------------------------------------------------------------------------------------------

      // 明细变量==================================================================================================
      disableEdit: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品工艺明细表格数据
      productTechDetailList: [],

      //铝盖信息是否显示
      isAlShow: false,
      //塑盖信息是否显示
      isPlShow: false,
      //包装信息是否显示
      isPKGShow: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 铝盖型式字典
      alCapOpenTypeOptions: [],
      // 铝盖商标字典
      alCapTrademarkOptions: [],
      // 铝带涂层字典
      alStripCoatOptions: [],
      // 铝带轧制字典
      alStripCastOptions: [],
      // 塑盖形状字典
      plCapShapeOptions: [],
      // 塑盖表面字典
      plCapSurfaceOptions: [],
      // 塑盖商标字典
      plCapTrademarkOptions: [],
      // 铆点型式字典
      plCapRivetTypeOptions: [],
      // 塑袋尺寸字典
      pkgPlbSizeOptions: [],
      // 塑袋厚度字典
      pkgPlbThickOptions: [],
      // 塑袋层数字典
      pkgPlbLayerOptions: [],
      // 封口方式字典
      pkgSealTypeOptions: [],
      // 袋包装量字典
      pkgBagPackNumOptions: [],
      // 箱包装量字典
      pkgCasePackNumOptions: [],
      // 内贴标签字典
      pkgInLabelOptions: [],
      // 纸箱尺寸字典
      pkgCartonSizeOptions: [],
      // 纸箱印刷字典
      pkgCartonPrintOptions: [],
      // 纸箱色条字典
      pkgCartonColorOptions: [],
      // 纸箱层数字典
      pkgCartonLayerOptions: [],
      // 箱内垫板字典
      pkgPlateOptions: [],
      // 标签数量字典
      pkgLabelNumOptions: [],
      // 打包形式字典
      pkgPackTypeOptions: [],
      // 印章内容字典
      pkgStampContentOptions: [],
      // 整盘包装字典
      pkgPackAllOptions: [],
      // 是否有效字典
      deleteFlagOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        smesProductTechNo: null,
        techProcedureNo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        smesProductTechNo: [
          { required: true, message: "产品工艺编号不能为空", trigger: "blur" }
        ],
        techProcedureNo: [
          { required: true, message: "工艺流程编号不能为空", trigger: "blur" }
        ]
      },
      // 明细变量==================================================================================================
      // 遮罩层
      loading: true,

      // 显示搜索条件
      showPTSearch: true,
      // 总条数
      totalPT: 0,
      totalTP: 0,
      // 产品工艺表格数据
      productTechList: [],
      // 弹出层标题
      ptTitle: "",
      // 是否显示弹出层
      ptOpen: false,
      // 是否有效字典
      deleteFlagOptions: [],
      techProcessList: [],
      oldTechProcessNo: "",
      // 查询参数
      queryPTParams: {
        pageNum: 1,
        pageSize: 10,
        smesProductTechNo: null,
        productNo: null,
        techProcessNo: null,
        productName: null,
        techProcessName: null
      },
      //选中的产品工艺
      chosenProductTech: {
        toString: "",
        smesProductTechNo: null,
        techProcessNo: null,
        productNo: null,
        productName: null,
        techProcessName: null
      },
      // 表单参数
      formPT: {},
      // 表单校验
      rulesPT: {
        smesProductTechNo: [
          { required: true, message: "产品工艺编号不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getPTList();
    this.getTechProcessList();
    this.getDicts("sys_yes_no").then(response => {
      this.deleteFlagOptions = response.data;
      this.pkgPackAllOptions = response.data;
      this.pkgInLabelOptions = response.data;
    });
    this.getDicts("al_cap_open_type").then(response => {
      this.alCapOpenTypeOptions = response.data;
    });
    this.getDicts("trademark_type").then(response => {
      this.alCapTrademarkOptions = response.data;
    });
    this.getDicts("al_strip_coat").then(response => {
      this.alStripCoatOptions = response.data;
    });
    this.getDicts("al_strip_cast").then(response => {
      this.alStripCastOptions = response.data;
    });
    this.getDicts("pl_cap_shape").then(response => {
      this.plCapShapeOptions = response.data;
    });
    this.getDicts("pl_cap_surface").then(response => {
      this.plCapSurfaceOptions = response.data;
    });
    this.getDicts("trademark_type").then(response => {
      this.plCapTrademarkOptions = response.data;
    });
    this.getDicts("pl_cap_rivet_type").then(response => {
      this.plCapRivetTypeOptions = response.data;
    });
    this.getDicts("pkg_plb_size").then(response => {
      this.pkgPlbSizeOptions = response.data;
    });
    this.getDicts("pkg_plb_thick").then(response => {
      this.pkgPlbThickOptions = response.data;
    });
    this.getDicts("pkg_plb_layer").then(response => {
      this.pkgPlbLayerOptions = response.data;
    });
    this.getDicts("pkg_seal_type").then(response => {
      this.pkgSealTypeOptions = response.data;
    });
    this.getDicts("pkg_bag_pack_num").then(response => {
      this.pkgBagPackNumOptions = response.data;
    });
    this.getDicts("pkg_case_pack_num").then(response => {
      this.pkgCasePackNumOptions = response.data;
    });
    this.getDicts("pkg_carton_size").then(response => {
      this.pkgCartonSizeOptions = response.data;
    });
    this.getDicts("pkg_carton_print").then(response => {
      this.pkgCartonPrintOptions = response.data;
    });
    this.getDicts("pkg_carton_color").then(response => {
      this.pkgCartonColorOptions = response.data;
    });
    this.getDicts("pkg_carton_layer").then(response => {
      this.pkgCartonLayerOptions = response.data;
    });
    this.getDicts("pkg_plate").then(response => {
      this.pkgPlateOptions = response.data;
    });
    this.getDicts("pkg_label_num").then(response => {
      this.pkgLabelNumOptions = response.data;
    });
    this.getDicts("pkg_pack_type").then(response => {
      this.pkgPackTypeOptions = response.data;
    });
    this.getDicts("pkg_stamp_content").then(response => {
      this.pkgStampContentOptions = response.data;
    });
  },
  methods: {
    /** 查询产品工艺列表 */
    getPTList() {
      this.loading = true;
      listProductTech(this.queryPTParams).then(response => {
        this.productTechList = response.rows;
        this.totalPT = response.total;
        this.loading = false;
      });
    },
    getTechProcessList() {
      listTechProcess().then(response => {
        this.techProcessList = response.rows;
        this.totalTP = response.total;
      });
    },
    // 是否有效字典翻译
    deleteFlagFormat(row, column) {
      return this.selectDictLabel(this.deleteFlagOptions, row.deleteFlag);
    },
    // 取消按钮
    cancelPT() {
      this.ptOpen = false;
      this.resetPT();
    },
    initPTDialog() {
      this.$nextTick(() => {
        this.$refs.tptable.clearSelection();
        if (
          this.formPT.smesProductTechNo != null &&
          this.formPT.smesProductTechNo != ""
        ) {
          this.techProcessList.forEach(item => {
            if (item.techProcessNo == this.formPT.techProcessNo) {
              this.$refs.tptable.toggleRowSelection(item);
            }
          });
        }
      });
    },
    // 表单重置
    resetPT() {
      this.formPT = {
        rowId: null,
        smesProductTechNo: null,
        productNo: null,
        techProcessNo: null,
        productName: null,
        techProcessName: null,
        deleteFlag: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.oldTechProcessNo = "";
      //this.resetForm("formPT");
    },
    /** 搜索按钮操作 */
    handlePTQuery() {
      this.queryPTParams.pageNum = 1;
      this.getPTList();
    },
    /** 重置按钮操作 */
    resetPTQuery() {
      this.resetForm("queryPTForm");
      this.handlePTQuery();
    },
    // 选中产品工艺数据
    handleProductTechSelectionChange(row) {
      // this.chosenProductTech.smesProductTechNo = row.smesProductTechNo;
      // this.chosenProductTech.techProcessNo = row.techProcessNo;
      // this.chosenProductTech.techProcessName = row.techProcessName;
      // this.chosenProductTech.productNo = row.productNo;
      // this.chosenProductTech.productName = row.productName;
      console.log(row);
      if (row.techProcessNo != null && row.techProcessNo != "") {
        this.chosenProductTech.toString =
          "当前选中产品：" +
          row.productName +
          ";分配的工艺：" +
          row.techProcessName;
      } else {
        this.chosenProductTech.toString =
          "当前选中产品：" +
          row.productName +
          ";未分配工艺，请先为该产品分配工艺";
      }

      this.queryParams.smesProductTechNo = row.smesProductTechNo;
      this.getList();
    },
    rowTPClick(selection) {
      if (selection.length > 0) {
        this.formPT.techProcessNo = selection[0].techProcessNo;
        if (selection.length > 1) {
          this.$refs.tptable.clearSelection();
          this.$refs.tptable.toggleRowSelection(selection.pop());
        }
      }
    },
    // 产品工艺分配
    handleSelect(row) {
      this.resetPT();
      this.ptOpen = true;
      this.ptTitle = "产品工艺分配";
      this.formPT.productNo = row.productNo;
      this.formPT.productName = row.productName;
      this.formPT.techProcessNo = row.techProcessNo;
      this.formPT.smesProductTechNo = row.smesProductTechNo;
      this.oldTechProcessNo = row.techProcessNo;
      console.log(this.formPT);
    },
    /** 提交按钮 */
    submitPTForm() {
      if (this.formPT.smesProductTechNo != null) {
        if (this.formPT.techProcessNo != this.oldTechProcessNo) {
          const formPT = this.formPT;
          this.resetF();
          this.form.smesProductTechNo = this.formPT.smesProductTechNo;
          this.form.techProcessNo = this.formPT.techProcessNo;
          const form = this.form;
          const that = this;
          this.queryParams.smesProductTechNo = this.formPT.smesProductTechNo;
          listProductTechDetail(this.queryParams).then(response => {
            if (response.total > 0) {
              this.$confirm(
                "修改工艺分配将导致产品原有的工艺流程参数数据被删除！确认修改吗？",
                "警告",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                }
              ).then(function() {
                updateProductTech(formPT).then(response => {
                  delProductTechDetail(formPT.smesProductTechNo).then(
                    delresponse => {
                      addProductTechDetail(form).then(addresponse => {
                        that.msgSuccess("修改产品工艺分配成功！");
                        that.ptOpen = false;
                        that.getPTList();
                      });
                    }
                  );
                });
              });
            } else {
              updateProductTech(formPT).then(response => {
                addProductTechDetail(form).then(addresponse => {
                  this.msgSuccess("修改产品工艺分配成功！");
                  this.ptOpen = false;
                  this.getPTList();
                });
              });
            }
          });
        } else {
          this.msgInfo("工艺相同");
        }
      } else {
        this.formPT.smesProductTechNo = this.formPT.productNo + "_TP";
        this.form.smesProductTechNo = this.formPT.smesProductTechNo;
        this.form.techProcessNo = this.formPT.techProcessNo;
        addProductTech(this.formPT).then(response => {
          addProductTechDetail(this.form).then(addresponse => {
            this.msgSuccess("修改产品工艺分配成功！");
            this.ptOpen = false;
            this.getPTList();
          });
        });
      }
    },

    /** 导出按钮操作 */
    handleTPExport() {
      const queryPTParams = this.queryPTParams;
      this.$confirm("是否确认导出所有产品工艺数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportProductTech(queryPTParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    /** 查询产品工艺明细列表 */
    getList() {
      if (this.queryParams.smesProductTechNo == null) {
        this.productTechDetailList = null;
      } else {
        this.loading = true;
        listProductTechDetail(this.queryParams).then(response => {
          this.productTechDetailList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }
    },
    // 铝盖型式字典翻译
    alCapOpenTypeFormat(row, column) {
      return this.selectDictLabel(this.alCapOpenTypeOptions, row.alCapOpenType);
    },
    // 铝盖商标字典翻译
    alCapTrademarkFormat(row, column) {
      return this.selectDictLabel(
        this.alCapTrademarkOptions,
        row.alCapTrademark
      );
    },
    // 铝带涂层字典翻译
    alStripCoatFormat(row, column) {
      return this.selectDictLabel(this.alStripCoatOptions, row.alStripCoat);
    },
    // 铝带轧制字典翻译
    alStripCastFormat(row, column) {
      return this.selectDictLabel(this.alStripCastOptions, row.alStripCast);
    },
    // 塑盖形状字典翻译
    plCapShapeFormat(row, column) {
      return this.selectDictLabel(this.plCapShapeOptions, row.plCapShape);
    },
    // 塑盖表面字典翻译
    plCapSurfaceFormat(row, column) {
      return this.selectDictLabel(this.plCapSurfaceOptions, row.plCapSurface);
    },
    // 塑盖商标字典翻译
    plCapTrademarkFormat(row, column) {
      return this.selectDictLabel(
        this.plCapTrademarkOptions,
        row.plCapTrademark
      );
    },
    // 铆点型式字典翻译
    plCapRivetTypeFormat(row, column) {
      return this.selectDictLabel(
        this.plCapRivetTypeOptions,
        row.plCapRivetType
      );
    },
    // 塑袋尺寸字典翻译
    pkgPlbSizeFormat(row, column) {
      return this.selectDictLabel(this.pkgPlbSizeOptions, row.pkgPlbSize);
    },
    // 塑袋厚度字典翻译
    pkgPlbThickFormat(row, column) {
      return this.selectDictLabel(this.pkgPlbThickOptions, row.pkgPlbThick);
    },
    // 塑袋层数字典翻译
    pkgPlbLayerFormat(row, column) {
      return this.selectDictLabel(this.pkgPlbLayerOptions, row.pkgPlbLayer);
    },
    // 封口方式字典翻译
    pkgSealTypeFormat(row, column) {
      return this.selectDictLabel(this.pkgSealTypeOptions, row.pkgSealType);
    },
    // 袋包装量字典翻译
    pkgBagPackNumFormat(row, column) {
      return this.selectDictLabel(this.pkgBagPackNumOptions, row.pkgBagPackNum);
    },
    // 箱包装量字典翻译
    pkgCasePackNumFormat(row, column) {
      return this.selectDictLabel(
        this.pkgCasePackNumOptions,
        row.pkgCasePackNum
      );
    },
    // 内贴标签字典翻译
    pkgInLabelFormat(row, column) {
      return this.selectDictLabel(this.pkgInLabelOptions, row.pkgInLabel);
    },
    // 纸箱尺寸字典翻译
    pkgCartonSizeFormat(row, column) {
      return this.selectDictLabel(this.pkgCartonSizeOptions, row.pkgCartonSize);
    },
    // 纸箱印刷字典翻译
    pkgCartonPrintFormat(row, column) {
      return this.selectDictLabel(
        this.pkgCartonPrintOptions,
        row.pkgCartonPrint
      );
    },
    // 纸箱色条字典翻译
    pkgCartonColorFormat(row, column) {
      return this.selectDictLabel(
        this.pkgCartonColorOptions,
        row.pkgCartonColor
      );
    },
    // 纸箱层数字典翻译
    pkgCartonLayerFormat(row, column) {
      return this.selectDictLabel(
        this.pkgCartonLayerOptions,
        row.pkgCartonLayer
      );
    },
    // 箱内垫板字典翻译
    pkgPlateFormat(row, column) {
      return this.selectDictLabel(this.pkgPlateOptions, row.pkgPlate);
    },
    // 标签数量字典翻译
    pkgLabelNumFormat(row, column) {
      return this.selectDictLabel(this.pkgLabelNumOptions, row.pkgLabelNum);
    },
    // 打包形式字典翻译
    pkgPackTypeFormat(row, column) {
      return this.selectDictLabel(this.pkgPackTypeOptions, row.pkgPackType);
    },
    // 印章内容字典翻译
    pkgStampContentFormat(row, column) {
      return this.selectDictLabel(
        this.pkgStampContentOptions,
        row.pkgStampContent
      );
    },
    // 整盘包装字典翻译
    pkgPackAllFormat(row, column) {
      return this.selectDictLabel(this.pkgPackAllOptions, row.pkgPackAll);
    },
    // 是否有效字典翻译
    deleteFlagFormat(row, column) {
      return this.selectDictLabel(this.deleteFlagOptions, row.deleteFlag);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    resetF() {
      this.form = {
        rowId: null,
        smesProductTechNo: null,
        techProcedureNo: null,
        techProcedureName: null,
        currentProcessName: null,
        nextProcessName: null,
        alCapSpec: "/",
        alStripThick: "/",
        alCapInDiameter: "/",
        alCapInHeight: "/",
        alCapOpenType: "/",
        alCapTrademark: "/",
        alStripCoat: "/",
        alStripCast: "/",
        plCapOutCircle: "/",
        plCapColor: "/",
        plCapMasterbatch: "/",
        plCapShape: "/",
        plCapSurface: "/",
        plCapTrademark: "/",
        plCapRivetType: "/",
        pkgPlbSize: "/",
        pkgPlbThick: "/",
        pkgPlbLayer: "/",
        pkgSealType: "/",
        pkgBagPackNum: "/",
        pkgCasePackNum: "/",
        pkgInLabel: "/",
        pkgCartonSize: "/",
        pkgCartonPrint: "/",
        pkgCartonColor: "/",
        pkgCartonLayer: "/",
        pkgPlate: "/",
        pkgLabelNum: "/",
        pkgPackType: "/",
        pkgStampContent: "/",
        pkgPackAll: "/",
        deleteFlag: "Y",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
    },
    // 表单重置
    reset() {
      this.resetF();
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      this.open = true;
      this.title = "添加产品工艺明细";
    },
    resetShow() {
      this.isAlShow = false;
      this.isPKGShow = false;
      this.isPlShow = false;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const rowId = row.rowId || this.ids;
      this.resetShow();
      switch (row.workCenterNo) {
        case "W001":
          this.isAlShow = true;
          break;
        case "W002":
          this.isPlShow = true;
          break;
        case "W003":
          this.isPKGShow = true;
          break;
        case "W004":
          this.isAlShow = true;
          this.isPlShow = true;
          break;
      }

      if (rowId != null && rowId != "") {
        getProductTechDetail(rowId).then(response => {
          this.form = response.data;
          this.form.smesProductTechNo = row.smesProductTechNo;
          this.form.nextProcessName = row.nextProcessName;
          this.form.currentProcessName = row.currentProcessName;
          this.form.techProcedureNo = row.techProcedureNo;
          this.form.techProcedureName = row.techProcedureName;
          this.open = true;
          this.title = "修改产品工艺明细";
        });
      } else {
        this.form.smesProductTechNo = row.smesProductTechNo;
        this.form.nextProcessName = row.nextProcessName;
        this.form.currentProcessName = row.currentProcessName;
        this.form.techProcedureNo = row.techProcedureNo;
        this.form.techProcedureName = row.techProcedureName;
        this.open = true;
        this.title = "添加产品工艺明细";
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.rowId != null) {
            updateProductTechDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProductTechDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rowIds = row.rowId || this.ids;
      this.$confirm(
        '是否确认删除产品工艺明细编号为"' + rowIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delProductTechDetail(rowIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有产品工艺明细数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportProductTechDetail(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    handleDetailRowClick(row) {
      console.log(row);
      this.selectedDetailId = row.rowId;
      this.queryMParams.productTechDetailId = this.selectedDetailId;
      console.log("序号为：" + this.selectedDetailId + "的用料");
      this.getMaterialList();
    },
    /** 查询产品工艺用料列表 */
    getMaterialList() {
      this.loading = true;
      listProductTechMaterial(this.queryMParams).then(response => {
        this.productTechMaterialList = response.rows;
        this.totalMaterial = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancelptm() {
      this.ptmOpen = false;
      this.resetptm();
    },
    // 表单重置
    resetptm() {
      this.ptmForm = {
        rowId: null,
        productTechMaterialNo: null,
        productTechDetailId: null,
        materialNo: null,
        weight: null,
        deleteFlag: "Y",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("ptmForm");
    },
    /** 搜索按钮操作 */
    handleQueryMaterial() {
      this.queryMParams.pageNum = 1;
      this.getMaterialList();
    },
    // /** 重置按钮操作 */
    // 多选框选中数据
    handleMaterialSelectionChange(selection) {
      this.ptmIds = selection.map(item => item.productTechMaterialNo);
      this.ptmSingle = selection.length !== 1;
      this.ptmMultiple = !selection.length;
    },
    handleSelectMaterial() {
      this.selectMaterialOpen = true;
    },
    // 选中物料
    confirmSelectMaterial(data) {
      this.ptmForm.materialNo = data.materialNo;
      this.selectMaterialOpen = false;
    },
    cancelSelectMaterial() {
      this.selectMaterialOpen = false;
    },
    /** 新增按钮操作 */
    handleAddMaterial() {
      this.resetptm();
      this.ptmForm.productTechDetailId = this.selectedDetailId;
      this.ptmOpen = true;
      this.ptmTitle = "添加产品工艺用料";
    },
    /** 修改按钮操作 */
    handleUpdateMaterial(row) {
      this.resetptm();
      const productTechMaterialNo = row.productTechMaterialNo || this.ptmIds;
      getProductTechMaterial(productTechMaterialNo).then(response => {
        this.ptmForm = response.data;
        this.ptmOpen = true;
        this.ptmTitle = "修改产品工艺用料";
      });
    },
    /** 提交按钮 */
    submitptmForm() {
      this.$refs["ptmForm"].validate(valid => {
        if (valid) {
          if (this.ptmForm.rowId != null) {
            updateProductTechMaterial(this.ptmForm).then(response => {
              this.msgSuccess("修改成功");
              this.ptmOpen = false;
              this.getMaterialList();
            });
          } else {
            //编号为PTM_加上明细ID和物料号
            this.ptmForm.productTechMaterialNo =
              "PTM_" +
              this.ptmForm.productTechDetailId +
              "_" +
              this.ptmForm.materialNo;
            addProductTechMaterial(this.ptmForm).then(response => {
              this.msgSuccess("新增成功");
              this.ptmOpen = false;
              this.getMaterialList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDeleteMaterial(row) {
      const productTechMaterialNos = row.productTechMaterialNo || this.ptmIds;
      this.$confirm(
        '是否确认删除产品工艺用料编号为"' +
          productTechMaterialNos +
          '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delProductTechMaterial(productTechMaterialNos);
        })
        .then(() => {
          this.getMaterialList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExportMaterial() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有产品工艺用料数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportProductTechMaterial(queryMParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    }
  }
};
</script>
